<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Vendor_loads extends CI_Controller {

	     public function __construct()
       {
            parent::__construct();
		$this->load->helper("html");
		$this->load->helper("url");
		$this->load->helper('form');
		$this->load->helper('date');
		$this->load->model("vendor_loads_model");
		//$this->load->model("guest_comment_model");
		//$this->load->model("news_events_model");
		//$this->load->model("roomcottages_model");
		$this->load->helper(array('form', 'url'));
		$this->load->database();
		
	}
	
	//START ------------------Vendor Load---------------------
	function index()
	{
		$data['title']="Administrator Page";
		$data["list_vendor_loads"] = $this->vendor_loads_model->get_all_vendor_loads();	
		$this->load->view('vendor_loads_list_view',$data);
	}

	function view_vendor_loads()
	{
		$data['title']="Administrator Page";
		$code = $this->uri->segment(3);
		$data["list_vendor_loads"] = $this->vendor_loads_model->getvendor_loads_info($code);
		$this->load->view('vendor_loads_list_view',$data);
	}
		
	function add_vendor_loads()
	{
		$data['title']="Administrator Page";
		$code = $this->uri->segment(3);
		$data["list_vendor_loads"] = $this->vendor_loads_model->getvendor_loads_info($code);
		$this->load->view('vendor_loads_add_view',$data);
	}
	function p_add_vendor_loads()
	{
		
		$this->load->database();			
		$order_date =$_POST['txtorder_date'];
		$vendor_id =$_POST['hid_vendor_id'];
		$client_id =$_POST['txtclient_id'];
		$rejob_id =$_POST['txtrejob_id'];
		$n_name =$_POST['txtn_name'];
		$pick_up_city =$_POST['txtpick_up_city'];
		$pick_up_state =$_POST['txtpick_up_state'];
		$pick_up_date =$_POST['txtpick_up_date'];			
		$drop_off_city =$_POST['txtdrop_off_city'];
		$drop_off_state =$_POST['txtdrop_off_state'];
		$drop_off_date =$_POST['txtdrop_off_date'];
		$contract_amount =$_POST['txtcontract_amount'];
		$createdby_id =$_POST['txtcreatedby_id'];
		$comment_box =$_POST['txtcomment_box'];
								 
		$_sql="insert into vendor_loads(order_date,vendor_id, client_id,rejob_id,n_name,pick_up_city,pick_up_state,pick_up_date,drop_off_city,drop_off_state,drop_off_date,contract_amount,createdby_id,comment_box)";
		$_sql.="values('$order_date','$vendor_id','$client_id','$rejob_id','$n_name','$pick_up_city','$pick_up_state','$pick_up_date','$drop_off_city','$drop_off_state','$drop_off_date','$contract_amount','$createdby_id','$comment_box')";
		$query = $this->db->query($_sql); 
		$vendor_id=$this->db->insert_id();
	 
		$_sql="INSERT into vendor_loads (vendor_id) SELECT profile_id FROM profile";
		$query = $this->db->query($_sql); 

		$data["list_vendor_loads"] = $this->vendor_loads_model->get_all_vendor_loads();	
		$this->load->view('vendor_loads_list_view',$data);
							
	}
	
	function edit_vendor_loads()
	{
 	    $code = $this->uri->segment(3);
		$data["info"] = $this->vendor_loads_model->getvendor_loads_info($code);	
		$this->load->view('vendor_loads_edit_view',$data);
	}
	
	function p_edit_vendor_loads()
	{
		$this->load->database();
		    $vload_id= $_POST['hid_vloadid'];
			$order_date = $_POST['txtorder_date'];
			$client_id = $_POST['txtclient_id'];
			$rejob_id = $_POST['txtrejob_id'];
			$n_name = $_POST['txtn_name'];
			$pick_up_city = $_POST['txtpick_up_city'];
			$pick_up_state = $_POST['txtpick_up_state'];
			$pick_up_date = $_POST['txtpick_up_date'];
			$drop_off_city  = $_POST['txtdrop_off_city'];
			$drop_off_state = $_POST['txtdrop_off_state'];
			$drop_off_date = $_POST['txtdrop_off_date'];
			$contract_amount = $_POST['txtcontract_amount'];
			$createdby_id = $_POST['txtcreatedby_id'];
			$comment_box = $_POST['txtcomment_box'];
			$query = $this->db->query("UPDATE profile SET 
											  		      order_date='$order_date',
														  client_id='$client_id', 
														  rejob_id='$rejob_id',
														  n_name='$n_name',
														  pick_up_city='$pick_up_city',
														  pick_up_state='$pick_up_state',
														  pick_up_date='$pick_up_date',
														  drop_off_city='$drop_off_city',
														  drop_off_state='$drop_off_state',
														  drop_off_date='$drop_off_date',
  											  			  contract_amount ='$contract_amount';
 														  createdby_id='$createdby_id',
														  comment_box='$comment_box'"); 			
			
	
			
		$data["list_vendor_loads"] = $this->vendor_loads_model->get_all_vendor_loads();	
		$this->load->view('vendor_loads_list_view',$data);		
	}
	
	function delete_vendor_loads()
	{
		$this->load->database();		
		$code = $this->uri->segment(3);
		$query = $this->db->query("delete from vendor_loads where vload_id='$code'");
		
		$data["list_vendor_loads"] = $this->vendor_loads_model->get_all_vendor_loads();	
		$this->load->view('vendor_loads_list_view',$data);
	}
	//END ------------------Vendor---------------------
	
	function logout()
	{
		
		//$this->load->library('session');
		//$this->session->sess_destroy();
		session_start();
		session_destroy();
		//echo $_SESSION['Administrator_log'];
		//unset($_SESSION['Administrator_log']);
		
			//$data["newsresult"] = $this->vendor_loads_model->dv_all_driver_vendor();
			$this->load->view('home_view');
	 
	}
 
}
?>